home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 10
/
FM Towns Free Software Collection 10.iso
/
ms_dos
/
tool
/
fapxtool
/
src
/
txm
/
txmhp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-01-06
|
4KB
|
183 lines
/***************
*
* txm\txmhp.c
*/
#include "txm.h"
#if 0
/* マージファイル更新チェック/必要ならマージファイルを新しくする/情報ファイル更新(HP用) */
int hchknewmerge(char *buf, FILE **fp)
{
long article; /* 発言番号 */
union _LONG ltime;
int year = 0, month = 0, day = 0, hour = 0, minute = 0;
unsigned short ym = 0, dhm = 0;
int newflag = FALSE;
char ext[6];
article = atol(buf);
sscanf(buf+5, "[%2d/%2d/%2d %2d:%2d]",
&year, &month, &day, &hour, &minute);
ym = (year << 4) | month;
dhm = (day << 11) | (hour << 6) | minute;
ltime.s.h = ym;
ltime.s.l = dhm;
switch (nextmerge) {
case 0:
if (filelength(fileno(*fp)) >= nextvalue) {
newflag = TRUE;
}
break;
case 1:
if (nextvalue == 1) {
if (nowinfo->art > article) {
newflag = TRUE;
}
}
else if ((article % nextvalue) == 1) {
newflag = TRUE;
}
break;
case 2:
if (nowinfo->ltime.s.h != 0) {
if (nowinfo->ltime.s.h < ym) {
newflag = TRUE;
}
}
break;
}
if (nowinfo->ltime.x > ltime.x) {
newflag = FALSE;
}
else {
nowinfo->ltime.x = ltime.x;
}
if (nowinfo->art == 0) {
newflag = FALSE;
}
nowinfo->art = (unsigned short)article;
if (newflag) {
fclose(*fp);
nowinfo->ext += 1;
sprintf(ext, ".%03d", nowinfo->ext);
makenewextname(logfile, mfile, ext);
if ((*fp = fopen(mfile, "wb")) == NULL) {
return ERROR;
}
fputs(head1, *fp);
fputs(head2, *fp);
fputs(mesname, *fp);
}
else {
return FALSE;
}
return TRUE;
}
#endif
/* HPマージ */
int hpmerge()
{
FILE *fr, *fw, *fm;
int ret;
long nowsize, limitsize;
char *vbuf;
/* printf("hpmerge()\n"); */
if ((fr = fopen(logfile, "rb")) == NULL) {
return FALSE;
}
/* setvbufのmallocは取りっ放し(終了時の自動開放??) */
setvbuf(fr, malloc(VBUFSIZE), _IOFBF, VBUFSIZE);
if ((fm = fopen(mfile, "ab")) == NULL) {
fclose(fr);
return FALSE;
}
/* setvbufのmallocは取りっ放し(終了時の自動開放??) */
setvbuf(fm, vbuf = malloc(VBUFSIZE), _IOFBF, VBUFSIZE);
fgets(head1, 80, fr); /* ヘッダ読み込み */
fgets(head2, 80, fr); /* ヘッダ読み込み */
limitsize = (long)minrun * 1024;
nowsize = filelength(fileno(fr));
nowsize -= strlen(head1);
nowsize -= strlen(head2);
if (fgets(line1, 100, fr) == NULL) {
nowsize = 0;
}
nowsize -= strlen(line1);
while (!matchstr(log_hp, line1)) {
strcpy(mesname, line1);
if (fgets(line1, 100, fr) == NULL) {
nowsize = 0;
break;
}
nowsize -= strlen(line1);
}
if (filelength(fileno(fm)) == 0) {
fputs(head1, fm);
fputs(head2, fm);
fputs(mesname, fm);
}
while (nowsize > limitsize) {
if (ret = fchknewmerge(line1, line1+6, &fm)) {
if (ret == ERROR) {
fclose(fr);
return FALSE;
}
}
fputs(line1, fm);
for(;;) { /* デリミタまたは次の発言まで発言転送 */
if (fgets(line1, 82, fr) == NULL) {
break;
}
nowsize -= strlen(line1);
if (*((long *)line1) == 0x0a0d0820) { /* デリミタ(リトルエンディアン用) */
if (fgets(line1, 82, fr) == NULL) {
break;
}
nowsize -= strlen(line1);
strcpy(mesname, line1);
if (fgets(line1, 82, fr) == NULL) {
break;
}
nowsize -= strlen(line1);
}
if (matchstr(log_hp, line1)) {
break;
}
fputs(line1, fm);
}
}
fclose(fm);
if ((fw = fopen(workfile, "wb")) == NULL) {
fclose(fr);
return FALSE;
}
setvbuf(fw, vbuf, _IOFBF, VBUFSIZE);
fputs(head1, fw);
fputs(head2, fw);
fputs(mesname, fw);
fputs(line1, fw);
while (fgets(line1, 82, fr)) {
fputs(line1, fw);
}
fclose(fr);
fclose(fw);
return TRUE;
}